package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.RoleBean;
import com.project.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("role")
@Api(tags = "角色")
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @RequestMapping("findAllRole")
    @ApiOperation(value = "查询所有角色")
    public List<RoleBean> findAllRole(){
        return roleService.findAllRole();
    }
    @RequestMapping("findByItem")
    @ApiOperation(value = "分页查询角色信息")
    public IPage<RoleBean> findByItem(Integer pageNO){
       return roleService.findByItem(pageNO);
    }
    @RequestMapping("add")
    @ApiOperation(value = "添加")
    public String add(String roleName,Integer[] gradeIdArray){
        if (roleService.add(roleName,gradeIdArray)){
            return "ok";
        }else {
            return "no";
        }
    }
    @RequestMapping("del")
    @ApiOperation(value = "删除")
    public String del(Integer roleId){
        roleService.del(roleId);
        return "ok";
    }
    @RequestMapping("findById")
    @ApiOperation(value = "查看角色的权限")
    public RoleBean findById(Integer roleId){
        return roleService.findById(roleId);
    }
    @RequestMapping("update")
    @ApiOperation(value = "修改角色的权限")
    public String update(Integer roleId,Integer[] gradeIdArray){
        roleService.update(roleId, gradeIdArray);
        return "ok";
    }
}
